package com.admin.education.dataTransferObject.votes.Mapper;

import com.admin.education.dataTransferObject.votes.Request.CreateVotesDetailRequest;
import com.admin.education.dataTransferObject.votes.Request.UpdateVotesDetailRequest;
import com.admin.education.dataTransferObject.votes.Request.UpdateVotesRequest;
import com.admin.education.dataTransferObject.votes.VotesDetailTransfer;
import com.admin.education.models.VotesDetail;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.Mappings;

import java.util.List;

@Mapper
public abstract class VotesDetailMapper {
    @Mappings({})
    public abstract VotesDetailTransfer mapFrom(VotesDetail votesDetail);
    @Mappings({})
    public abstract List<VotesDetailTransfer> mapFrom(List<VotesDetail> votesDetails);
    @Mappings({})
    public abstract VotesDetail mapFrom(CreateVotesDetailRequest createVotesDetailRequest);
    @Mappings({})
    public abstract List<VotesDetail> mapFromCreateEntity(List<CreateVotesDetailRequest> createVotesDetailRequests);
    @Mappings({})
    public abstract VotesDetail mapFrom(UpdateVotesDetailRequest updateVotesDetailRequest);
    @Mappings({})
    public abstract List<VotesDetail> mapFromUpdateEntity(List<UpdateVotesDetailRequest> updateVotesDetailRequests);
    @AfterMapping
    public void afterMapping(VotesDetail votesDetail, @MappingTarget VotesDetailTransfer votesDetailTransfer){
        if(null!=votesDetail.getVotesResults())
            votesDetailTransfer.setNumberOfVotes(votesDetail.getVotesResults().size());
    }
}
